#include "process.h"

#define TARGET_SIZE 1024 * 1024 //总下载量
#define DSIZE 1024 * 10 //单次下载量
#define STIME 1000 * 50 //单次下载时间

void download()
{
    double target = TARGET_SIZE;
    double total = 0;
    int cnt = 100;
    while (total <= target)
    {
        total += DSIZE;
        if (cnt > 0 && total > TARGET_SIZE / 2)
        {
            cnt--;
        }
        process_3(total * 100.0 / target);
        usleep(STIME);
    }
    printf("\n");
}

// 通过回调函数调用
void func(callback cb)
{
    int target = TARGET_SIZE;
    int total = 0;
    while (total <= target)
    {
        total += DSIZE;
        int rate = total * 100 / target;
        cb(rate);
        usleep(STIME);
    }
    printf("\n");
}

int main()
{
    //func(process_2);
    //for (int i = 0; i <= 100; ++i)
    //{
    //    process_2(i);
    //    usleep(STIME);
    //}
    
    download();

    return 0;
}
